package com.dudu.timer;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.log4j.Logger;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import com.dudu.bean.IfControlBean;
import com.dudu.dao.InfoControlDao;
import com.dudu.service.IInfoControl;
import com.dudu.service.impl.InfoControlServiceImpl;

import net.sf.json.JSONObject;

/**
 * 处于信控中的语音通知
 * 如果信控未审核处理，自动处理语音通知的发送状态，调整为0-待发送
 * @author zx
 *
 */
@DisallowConcurrentExecution
public class InfoControlStatusUpdaterJob implements Job {
	private static final Logger log = core.util.Logger.getLogger(InfoControlStatusUpdaterJob.class.getSimpleName());
	private static IInfoControl control = new InfoControlServiceImpl();

	@Override
	public void execute(JobExecutionContext context) throws JobExecutionException {
		InfoControlDao dao = new InfoControlDao();
		List<JSONObject> list = dao.queryInfoControlCheckOverTimeList();
		if (CollectionUtils.isNotEmpty(list)) {
			for (int i = 0; i < list.size(); i++) {
				JSONObject infoControl = list.get(i);
				int id = infoControl.getInt("id");
				IfControlBean ifBean = new IfControlBean();
				ifBean.setChecker("system");// 系统自动处理
				ifBean.setId(id);
				ifBean.setCheckConclusion("Y");// 通过
				if (control.finishInfoControlOverTime(ifBean)) {
					ifBean.setAbilityType(infoControl.getString("ability_type"));
					ifBean.setAppKey(infoControl.getString("app_key"));
					ifBean.setBatchNumber(infoControl.getString("batch_number"));
					ifBean.setCustAccount(infoControl.getString("cust_account"));
					dao.updateVoiceStatus(ifBean);
				}
			}
		}
	}

}
